home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / 80x0393.zip / NOCAD.ASM < prev    next >
Assembly Source File  |  1992-07-30  |  3KB  |  128 lines

  1. ;
  2. ; NOCAD.ASM     a control-alt-delete interrupt handler
  3. ;
  4. ; June 23, 1992  Paul Cullum
  5. ;
  6. ; Modified by David Kirschbaum aka Toad Hall fixing problems
  7. ; relating to segment registers.  Thanks a lot David.
  8. ; Released into the public domain.
  9. ;
  10.  
  11.         .MODEL small, c
  12.  
  13.         CTRLALT  EQU  8h OR 4h
  14.         DELSCAN  EQU  53h
  15.         KBPORT   EQU  60h
  16.         CONTPORT EQU  20h
  17.  
  18.         .CODE
  19.  
  20. ;  Function:    disablecad
  21. ;  Parameters:  an offset to a word is passed to flag a CTRL-C/BREAK
  22. ;  Description: sets up a new keyboard handler
  23. ;
  24.  
  25. disablecad PROC near
  26.  
  27. flag    EQU     [bp+4]                  ;address of flag variable
  28.  
  29.         push  bp                        ;save BP
  30.         mov   bp, sp                    ;set up stack frame
  31.  
  32.         mov   ax, flag                  ;mov address into AX
  33.         mov   word ptr cs:flagptr, ax   ;save the word's offset in flag
  34.         mov   word ptr cs:flagptr+2, ds ;
  35.         mov   ax, 3509h                 ;save the old handler's address
  36.         int   21h
  37.         mov   word ptr cs:oldkbhandler, bx
  38.         mov   word ptr cs:oldkbhandler+2, es
  39.         push  ds
  40.         push  cs
  41.         pop   ds
  42.         mov   dx, offset cs:newkbhandler
  43.         mov   ax, 2509h                 ;set new handler as interrupt
  44.         int   21h
  45.         pop   ds
  46.  
  47.         pop bp
  48.         ret
  49.  
  50.         flagptr       dd     0
  51.         oldkbhandler  dd     0
  52.  
  53. disablecad ENDP
  54.  
  55.  
  56. ;
  57. ;  Function:    enablecad
  58. ;  Parameters:  none
  59. ;  Description: restores original handler
  60. ;
  61. enablecad PROC near
  62.  
  63.         push  ds
  64.         push  ax
  65.         push  dx
  66.  
  67.         lds   dx, cs:oldkbhandler
  68.         mov   ax, 2509h
  69.         int   21h
  70.  
  71.         pop dx
  72.         pop ax
  73.         pop ds
  74.         ret
  75.  
  76. enablecad ENDP
  77.  
  78.  
  79. ;
  80. ;  Function:    newkbhandler
  81. ;  Parameters:  none
  82. ;  Description: ctrl-break handler, sets a flag
  83. ;
  84. newkbhandler PROC far
  85.         push  ax
  86.  
  87.         in    al, KBPORT         ;read scancode of key that caused interrupt
  88.         cmp   al, DELSCAN        ;check to see if it is DEL
  89.         jne   notcad             ;if not call to old handler
  90.  
  91.         push  ds
  92.         xor   ax,ax
  93.         mov   ds, ax
  94.         mov   al, ds:[417h]      ;reads keyboard flags
  95.         pop   ds                 ;done with it
  96.         and   al, CTRLALT        ;and it with CTRLALT flags
  97.         cmp   al, CTRLALT        ;compare it to CTRLALT flags
  98.         jne   notcad             ;if not call old handler
  99.  
  100.         push  bx                 ;save BX
  101.         push  ds                 ;and DS 
  102.         lds   bx, cs:flagptr     ;set the CTRL-ALT-DEL flag
  103.         mov   word ptr [bx], 1   
  104.         pop   ds                 ;restore
  105.         pop   bx                 ;done with it
  106.  
  107.         in    al, KBPORT + 1
  108.         mov   bl, al
  109.         or    al, 80h
  110.         out   KBPORT + 1, al
  111.         mov   al, bl
  112.         out   KBPORT + 1, al
  113.         mov   al, 20h
  114.         cli
  115.         out   CONTPORT, al
  116.         sti
  117.         jmp   short done
  118.  
  119. notcad: pushf                ;fake an interrupt
  120.                              ;(remember, the old handler is gonna
  121.                              ;IRET back to us!)
  122.         call  cs:[oldkbhandler]     ;call to old handler
  123.  
  124. done:   pop   ax               ;only reg still on the stack
  125.         iret
  126. newkbhandler ENDP
  127. END
  128.